<template>
	<view>
		<uni-search-bar  :focus="true" v-model="searchForm.sorder" @confirm="refreshList()" />
		<uni-table border stripe emptyText="暂无更多数据" >
			<uni-tr>
				<uni-th align="center">选择</uni-th>
				<uni-th align="center">条码</uni-th>
				<uni-th align="center">订单号</uni-th>
				<uni-th align="center">款号</uni-th>
				<uni-th align="center">颜色</uni-th>
				<uni-th align="center">尺码</uni-th>
				<uni-th align="center">工厂</uni-th>
				<uni-th align="center">包号</uni-th>
				<uni-th align="center">数量</uni-th>
				<uni-th align="center">床次</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in tableData" :key="index">
		      <uni-td align="center">
				  <u-button type="info" size="mini" :plain="true"  @click="handleClick(item)">
					  选择
				  </u-button>
			  </uni-td>
		      <uni-td align="center">{{ item.sbarcode }}</uni-td>
		      <uni-td align="center">{{ item.sorder_no }}</uni-td>
		      <uni-td align="center">{{ item.sstyle_no }}</uni-td>
		      <uni-td align="center">{{ item.scolor_name }}</uni-td>
		      <uni-td align="center">{{ item.ssize_name }}</uni-td>
		      <uni-td align="center">{{ item.sFactoryName }}</uni-td>
		      <uni-td align="center">{{ item.spackage_no }}</uni-td>
		      <uni-td align="center">{{ item.iqty }}</uni-td>
		      <uni-td align="center">{{ item.sbed_order }}</uni-td>
			</uni-tr>
		</uni-table>
		 <uni-pagination 
		      :total="tablePage.total"
		      :current="tablePage.currentPage"
		      :pageSize="tablePage.pageSize"
		      @change="handlePageChange"
		      title="分页"
		 />

	</view>
</template>

<script>
	import rfidOutput from "@/api/report/rfidOutput"
	export default {
		data() {
			return {
				tablePage: {
					total: 0,
					currentPage: 1,
					pageSize: 10,
					orders: [{column: "create_time", asc: false}],
				},
				searchForm: {
					sorder: ''
				},
				tableData:[],
			}
		},
		onLoad() {
			this.refreshList()
		},
		methods: {
			refreshList(){
				uni.showLoading({
					title: '加载中'
				});
				rfidOutput.getPackageBillDtl({
					'current': this.tablePage.currentPage,
					'size': this.tablePage.pageSize,
					'orders': this.tablePage.orders,
					...this.searchForm
				}).then(data => {
					this.tableData = data.records
					this.tablePage.total = data.total
					uni.hideLoading();
				})
			},
			handleClick(item){				
				uni.showLoading({
					title: '保存中'
				});
				const params = {
					spackBarCode: item.sbarcode,
					dbeginDate: this.formatDateTime(new Date()),
					stype: '0',
				}			
				rfidOutput.saveRfidOutPut(params).then(res => {
					uni.hideLoading();
					if (res && res === 'ok') {
						 uni.showToast({
						 	title: '计时成功',
						 	icon: 'success'
						 });
						 setTimeout(() => {
						   uni.$emit('refreshData');
						   uni.navigateBack();
						 }, 300);
					 } else {
						 uni.showToast({
						 	title: res || '条码保存失败',
						 	icon: 'error'
						 });
					}
				})
			},	
			formatDateTime(date){
				const year = date.getFullYear()
				const month = String(date.getMonth() + 1).padStart(2, '0')
				const day = String(date.getDate()).padStart(2, '0')
				const hours = String(date.getHours()).padStart(2, '0')
				const minutes = String(date.getMinutes()).padStart(2, '0')
				const seconds = String(date.getSeconds()).padStart(2, '0')		
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
			},	
				
			handlePageChange({current}) {
			    this.tablePage.currentPage = current
			    this.refreshList()
			}   
		}
	}
</script>

<style>

</style>
